﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Forecast.Domain.Implementation
{
    class Buy : Offer
    {
        public Buy(IPlay creator, IPredict prediction, int numStocks, int price, DateTime expiryDate) 
            : base(creator, prediction, numStocks, price, expiryDate)
        {
            ICountStocks holding = creator.Portfolio.GetHolding(prediction);
            if (holding.NumStocks < numStocks)
                throw new ApplicationException(String.Format("{0} does not have enough of {1} to create this offer." +
                    Environment.NewLine + "{0} only has {2} of {1} not offered already.",
                    creator.Name,
                    prediction.Ticker,
                    holding.NumNotForSale));
            
            holding.PutUpForSale(numStocks);
        }
    }
}
